name: Test

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    name: Run tests
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Install dependencies
        run: yarn

      - name: Create empty .env
        run: touch .env

      - name: Run jest
        run: yarn test --coverage
        env:
          QIWI_TOKEN: ${{ secrets.QIWI_TOKEN }}
          QIWI_WALLET: ${{ secrets.QIWI_WALLET }}
          QIWI_SECRET_KEY: ${{ secrets.QIWI_PK }}
          QIWI_PUBLIC_KEY: ${{ secrets.QIWI_PUBK }}

      - name: Upload coverage to Codecov
        run: npx codecov
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

      - name: Upload coverage to Codacy
        run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
        env:
          CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
